package com.example.takeaway.controller;


import com.example.takeaway.entity.Address;
import com.example.takeaway.utils.PassToken;
import com.example.takeaway.utils.ServerResponse;
import com.example.takeaway.serivce.IAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * addressController
 * 
 * @author ruoyi
 * @date 2025-05-08
 */
@RestController
@RequestMapping("/system/address")
public class AddressController
{
    @Autowired
    private IAddressService addressService;

    /**
     * 查询address列表
     */
    @PassToken
    @GetMapping("/list")
    public ServerResponse list(Address address)
    {
//        startPage();
        List<Address> list = addressService.selectAddressList(address);
        return ServerResponse.createBysuccess(200,list,"查询成功");
    }

    /**
     * 导出address列表
     */
//    @PreAuthorize("@ss.hasPermi('system:address:export')")
//    @Log(title = "address", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Address address)
//    {
//        List<Address> list = addressService.selectAddressList(address);
//        ExcelUtil<Address> util = new ExcelUtil<Address>(Address.class);
//        util.exportExcel(response, list, "address数据");
//    }

    /**
     * 获取address详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:address:query')")
    @GetMapping(value = "/{addressid}")
    public ServerResponse getInfo(@PathVariable("addressid") Long addressid)
    {
        Address address = addressService.selectAddressByAddressid(addressid);
        return ServerResponse.createBysuccess(200,address,"查询成功");
    }

    /**
     * 新增address
     */
//    @PreAuthorize("@ss.hasPermi('system:address:add')")
//    @Log(title = "address", businessType = BusinessType.INSERT)
    @PostMapping
    public ServerResponse add(@RequestBody Address address)
    {

        int i = addressService.insertAddress(address);
        if(i>0){
            return ServerResponse.createBysuccess(200,"","添加成功");
        }else {
            return ServerResponse.createByfail(200,"添加失败");
        }
    }

    /**
     * 修改address
     */
//    @PreAuthorize("@ss.hasPermi('system:address:edit')")
//    @Log(title = "address", businessType = BusinessType.UPDATE)
    @PutMapping
    public ServerResponse edit(@RequestBody Address address)
    {
        int i = addressService.updateAddress(address);

        if(i>0){
            return ServerResponse.createBysuccess(200,"","修改成功");
        }else {
            return ServerResponse.createByfail(200,"修改失败");
        }
    }

    /**
     * 删除address
     */
//    @PreAuthorize("@ss.hasPermi('system:address:remove')")
//    @Log(title = "address", businessType = BusinessType.DELETE)
	@DeleteMapping("/{addressids}")
    public ServerResponse remove(@PathVariable Long[] addressids)
    {
        int i = addressService.deleteAddressByAddressids(addressids);
        if(i>0){
            return ServerResponse.createBysuccess(200,"","删除成功");
        }else {
            return ServerResponse.createByfail(200,"删除失败");
        }
    }
}
